package com.cqs.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

/**
 * @Author lixw
 * @Date 7/19/20 1:57 PM
 */
@RestController
@RequestMapping
@Slf4j
public class HelloController {

	@Autowired
	ResourceLoader resourceLoader;

	@RequestMapping("/m1")
	public Object m1() {
		return System.currentTimeMillis();
	}

	@RequestMapping("/movie")
	public Object m2() throws IOException {
		ClassPathResource classPathResource = new ClassPathResource("movie.json");
		log.info("file:" + classPathResource.getFile().getAbsolutePath());
		String s = FileUtils.readFileToString(new File(classPathResource.getFile().getAbsolutePath()), Charset.forName("utf-8"));
		log.info("size:{}",s.length());
		return s;
	}

}
